package iterator;

/**
 * @Author: Ma JiBin
 * @Email: 1423553596@qq.com
 * @Date: 2018/9/12 10:44
 * @Description: 迭代器模式（Iterator Pattern）
 * 实现了两个迭代器类，分别是IMap和Name的迭代器
 */
public class Main {
    public static void main(String[] args) {
        Container namesRepository = new NameRepository();
        Iterator iterator = namesRepository.getIterator();

        IMap iMap = new IMap();
        Iterator iMapIterator = new IMapRepository(iMap).getIterator();
        iMap.put("name", "Tom");
        iMap.put("age", 18);
        iMap.put("high", 180);
        iMap.update("name", "Jane");
        iMap.put("phone",123455);
        iMap.remove("phone");

        System.out.println("IMap : ");
        for (; iMapIterator.hasNext(); ) {
            Object[] object = (Object[]) iMapIterator.next();
            System.out.println(object[0] + " : " + object[1]);
        }

        System.out.println("Names : ");
        for (; iterator.hasNext(); ) {
            String name = (String) iterator.next();
            System.out.println("Name : " + name);
        }
    }
}
